<template>
  <div>
    <h1>vue3-Worker</h1>
    <button @click="openWorker">开启线程</button>
    <p>F12打开浏览器控制台查看效果</p>
  </div>
</template>
<script>

</script>
<script setup>
import { onUnmounted } from 'vue';
import Worker from 'worker-loader!@/views/TestF/worker.js'

const worker = new Worker()

const openWorker = () => {
  worker.postMessage('开启线程')
  worker.onmessage = e => {
    console.log(e.data,222)
    setTimeout(() => {
      worker.postMessage('线程关闭')
      worker.terminate()
    }, 1000)
  }
}

// onUnmounted(() => {
//   console.log(1);
//   worker.terminate()
// })
</script>
<style scoped lang="scss"></style>
